//
// Created by tang on 2022/1/13.
//

#ifndef DIARYTOOL_TEXTURE_HPP
#define DIARYTOOL_TEXTURE_HPP

#include <memory>
#include <string>

#include "imgui/imgui.h"

class Texture {
    int   m_w_{};
    int   m_h_{};
    void *m_texture_;
public:
    Texture(const char* path);
    Texture(const std::string& path);
    ~Texture();

    ImTextureID Id() const;
    ImVec2 Size() const;
    bool Valid() const;
};

using TexturePtr = std::shared_ptr<Texture>;

namespace ImGui {
    void Image(const TexturePtr& texture, ImVec2 scale = { 1.f,1.f });
    void Image(const TexturePtr& texture, float width, float height);
    bool ImageButton(const char *str_id, const TexturePtr& texture, ImVec2 scale = { 1.f,1.f });
    bool ImageButton(const char *str_id, const TexturePtr& texture, float width, float height);
}

class TextureManager {
public:
    static void LoadAllTexture();
    static void FreeAllTexture();
    static TexturePtr Get(int id);
    static Texture* GetRaw(int id);
};

#endif //DIARYTOOL_TEXTURE_HPP
